define(['jquery', 'bootstrap', 'backend', 'table', 'form','upload','editable'], function ($, undefined, Backend, Table, Form, Upload)  {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fedition_ordershopifyd/index',
                    add_url: 'fedition_ordershopifyd/add',
                    edit_url: 'fedition_ordershopifyd/edit',
                    del_url: 'fedition_ordershopifyd/del',
                    multi_url: 'fedition_ordershopifyd/multi',
                    import_url: 'fedition_ordershopifyd/import',
                    table: 'fedition_ordershopify',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'updated_at',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        //{field: 'id', title: __('id'), operate: 'LIKE'},
                        //{field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'accounturl', title: __('Account_address'),visible: false,addClass: "selectpage", extend: "data-source='feditionaccounturl/index' data-field='name'"},
                        //{field: 'accounturl_name', title: __('Account_address'), operate: false},
                        //{field: 'tracking_company', title: __('运货公司'), operate: 'LIKE'},
                        {field: 'tracking_number', title: __('运单号'), operate: 'LIKE'},
                        {field: 'tracking_status', title: __('物流状态'), searchList: {"solicitation":__('揽件'),"way":__('在途'),"sign":__('签收'),"rejection":__('拒收')}, formatter: Table.api.formatter.status,custom: {rejection:'danger', sign:'success', way:'info', solicitation:'warning'}},
                        {field: 'tracking_time', title: __('最后更新时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('物流详情'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('查看物流详情'),
                                    title: __('查看物流详情'),
                                    extend: 'data-area=\'["90%","90%"]\'',
                                    classname: 'btn btn-sm btn-info btn-dialog',
                                    icon: 'fa fa-try fa-fw',
                                    url: 'fedition_orderopenpx/index?tracking_number={tracking_number}'
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                        {
                            field: 'buttons',
                            width: "120px",
                            title: __('更新物流'),
                            table: table,
                            events: Table.api.events.operate,
                            operate: false,
                            buttons: [
                                {
                                    name: 'ajax',
                                    text: __('追踪物流最新数据'),
                                    title: __('追踪物流最新数据'),
                                    classname: 'btn btn-sm btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-usd',
                                    confirm: '确认更新吗？',
                                    url: 'feditionordershopify/updateordertime',
                                    success: function (data, ret) {
                                        Layer.alert(ret.msg);
                                        //刷新父级页面
                                        // window.parent.location.reload();
                                        //刷新当前页面
                                        table.bootstrapTable('refresh', {});
                                        return true;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        },
                    ]
                ]
            });

            // 当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                $("#zcountnum").text(data.Statistics.zcountnum);
                $("#solicitation").text(data.Statistics.solicitation);
                $("#sign").text(data.Statistics.sign);
                $("#way").text(data.Statistics.way);
                $("#rejection").text(data.Statistics.rejection);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});